Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.
The merge npm package is a utility that allows you to merge multiple objects into one. It is useful when you want to combine configurations, settings, or other data structures in JavaScript. It performs a deep merge by default, meaning that it recursively merges properties of objects, but it can also be configured to perform a shallow merge.
Deep Merge
This feature allows for the deep merging of objects, meaning that nested objects will also be merged together. The code sample demonstrates merging two objects with nested properties.
{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge(object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }"}
Shallow Merge
This feature allows for the shallow merging of objects, which means that it will not recursively merge nested objects. The code sample demonstrates merging two objects without combining the nested properties.
{"const merge = require('merge');
const object1 = { a: 1, b: { c: 2 } };
const object2 = { b: { d: 3 }, e: 4 };
const mergedObject = merge.recursive(false, object1, object2);
console.log(mergedObject); // Output: { a: 1, b: { d: 3 }, e: 4 }"}
Lodash's merge function is similar to merge, offering deep merge capabilities. It is part of the larger Lodash library, which provides a wide range of utility functions for working with arrays, numbers, objects, strings, etc. Lodash is well-known for its performance and reliability.
Deepmerge is another npm package that provides deep merge functionality. It is designed to be more flexible than merge, allowing for custom merge strategies for specific fields and handling of arrays and other types that merge might not support out of the box.
Extend is a jQuery-inspired package that can perform both deep and shallow merges. It is lightweight and straightforward, but it does not offer as much control over the merge process as merge or deepmerge.
Object-assign is a polyfill for the Object.assign method, which performs a shallow merge of objects. It is built to match the ES6 specification for Object.assign and is useful for simple merging tasks where deep merge is not required.
Merge multiple objects into one, optionally creating a new cloned object. Similar to the jQuery.extend but more flexible. Works in Node.js and the browser.
npm install merge --save
var merge = require('merge'), original, cloned;
console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
console.log(original.x.y, cloned.x.y);
// -> 1, 2
console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/merge.js"></script>
<script>
var original, cloned;
console.log(merge({one:'hello'}, {two: 'world'}));
// -> {"one": "hello", "two": "world"}
original = { x: { y: 1 } };
cloned = merge(true, original);
cloned.x.y++;
console.log(original.x.y, cloned.x.y);
// -> 1, 2
console.log(merge.recursive(true, original, { x: { z: 2 } }));
// -> {"x": { "y": 1, "z": 2 } }
</script>
npm test
FAQs
(recursive)? merging of (cloned)? objects.
The npm package merge receives a total of 832,912 weekly downloads. As such, merge popularity was classified as popular.
We found that merge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.